#define QUERYESCSUPPORT 8

//The following are unique to Windows CE
#define GETVFRAMEPHYSICAL 6144
#define GETVFRAMELEN 6145
#define DBGDRIVERSTAT 6146
#define SETPOWERMANAGEMENT 6147
#define GETPOWERMANAGEMENT 6148

typedef enum _VIDEO_POWER_STATE {
VideoPowerOn = 1,
VideoPowerStandBy,
VideoPowerSuspend,
VideoPowerOff

} VIDEO_POWER_STATE, *PVIDEO_POWER_STATE;

typedef struct _VIDEO_POWER_MANAGEMENT {
ULONG Length;
ULONG DPMSVersion;
ULONG PowerState;
} VIDEO_POWER_MANAGEMENT, *PVIDEO_POWER_MANAGEMENT;

void DevicePowerScreen(BOOL bPowerOn)
{
VIDEO_POWER_MANAGEMENT vpm, vpmQuery;
BOOL bCurrentState = FALSE;
HDC g_hdc = GetDC(NULL); 

int iESC = SETPOWERMANAGEMENT;
if (ExtEscape(g_hdc, QUERYESCSUPPORT,
sizeof(int), (LPCSTR)&iESC,
0, NULL)==0)
return;

//Prevent the screen manager from
//attempting to turn the screen on if it's
//already on, and from turning the
//screen off if it's already off.

//This is a problem on some platforms,
//such as the iPAQ H3800 PocketPC 2002 platform.

memset(&vpm, 0, sizeof(vpm));
vpm.Length = sizeof(vpm);
vpm.DPMSVersion = 0x0001;

memset(&vpmQuery, 0, sizeof(vpmQuery));
vpmQuery.Length = sizeof(vpmQuery);
vpmQuery.DPMSVersion = 0x0001;

//Query the current screen power status

::ExtEscape(g_hdc, GETPOWERMANAGEMENT,
vpm.Length, (LPCSTR)&vpm,
vpmQuery.Length, (LPSTR)&vpmQuery);

bCurrentState =
((vpmQuery.PowerState > VideoPowerOn) ? FALSE : TRUE);

if (bPowerOn == bCurrentState)
return;

memset(&vpm, 0, sizeof(vpm));
vpm.Length = sizeof(vpm);
vpm.DPMSVersion = 0x0001;
vpm.PowerState = (bPowerOn ? VideoPowerOn : VideoPowerOff);

::ExtEscape(g_hdc, SETPOWERMANAGEMENT,
vpm.Length, (LPCSTR)&vpm, 0, NULL);
}